CREATE TABLE [dbo].[tb_NivelesEnsenanza]
(
[idNivelEnsenanza] [int] NOT NULL IDENTITY(1, 1),
[NivelEnsenanza] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Mnemo] [varchar] (5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[idnivelensenanzaAnses] [int] NULL,
[idNivelEnsenanzaFONID] [varchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE TRIGGER [dbo].[updatetb_NivelesEnsenanza] ON [dbo].[tb_NivelesEnsenanza]
 FOR UPDATE AS 
SET NOCOUNT ON
 IF (update(idNivelEnsenanza)) begin 
	 SELECT * FROM inserted 
	 IF @@ROWCOUNT = 1 begin 
		 UPDATE tb_Concursos
		 SET Nivel = (SELECT idNivelEnsenanza FROM inserted)
		 WHERE tb_Concursos.Nivel = (SELECT idNivelEnsenanza FROM deleted)
		 UPDATE tb_SubOrganizaciones
		 SET Nivel = (SELECT idNivelEnsenanza FROM inserted)
		 WHERE tb_SubOrganizaciones.Nivel = (SELECT idNivelEnsenanza FROM deleted)
	end  ELSE begin 
		 ROLLBACK TRANSACTION 
 end 
 end

GO
ALTER TABLE [dbo].[tb_NivelesEnsenanza] ADD CONSTRAINT [PK_tb_NivelesEnsenanza] PRIMARY KEY CLUSTERED  ([idNivelEnsenanza]) ON [PRIMARY]
GO
